package org.shoukaiseki.supersaiyan.generator.domain;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.ibatis.type.Alias;
import org.shoukaiseki.supersaiyan.common.constant.GenConstants;
import org.shoukaiseki.supersaiyan.common.utils.StringUtils;
import org.shoukaiseki.supersaiyan.generator.domain.entity.GenTableEntity;

/**
 * org.shoukaiseki.supersaiyan.generator.domain.GenTable
 * 业务表 gen_table
 * <br>
 *
 * @author shoukaiseki blog http://www.shoukaiseki.top/<br> E-mail jiang28555@Gmail.com<br>
 * @date 2022-10-15 14:49:16<br>
 */
@Alias("GenTable")
public class GenTable extends GenTableEntity
{
    private static final long serialVersionUID = 1L;

    public boolean isSub()
    {
        return StringUtils.equals(GenConstants.TPL_SUB, this.getTplCategory());
    }

    public boolean isTree()
    {
        return isTree(this.getTplCategory());
    }

    public static boolean isTree(String tplCategory){
        return StringUtils.equals(GenConstants.TPL_TREE, tplCategory);
    }

    public boolean isSksCrud()
    {
        return StringUtils.equals(GenConstants.TPL_SKS_CRUD, this.getTplCategory());
    }


    public boolean isCrud()
    {
        return StringUtils.equals(GenConstants.TPL_CRUD, this.getTplCategory());
    }



    public boolean isSuperColumn(String javaField)
    {
        return isSuperColumn(this.getTplCategory(), javaField);
    }

    public static boolean isSuperColumn(String tplCategory, String javaField)
    {
        if (isTree(tplCategory))
        {
            return StringUtils.equalsAnyIgnoreCase(javaField,
                    ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
        }
        return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
    }

}
